package com.example.liuxing.jdmall;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;

import com.example.liuxing.jdmall.activity.BaseActivity;
import com.example.liuxing.jdmall.fragement.CategoryFragment;
import com.example.liuxing.jdmall.fragement.HomeFragment;
import com.example.liuxing.jdmall.fragement.MineFragment;
import com.example.liuxing.jdmall.fragement.ShopFragment;
import com.example.liuxing.jdmall.listener.IBottomBarClickListener;
import com.example.liuxing.jdmall.ui.Bottom_bar;

public class MainActivity extends BaseActivity implements IBottomBarClickListener {

    private Bottom_bar bottom_bar;

    private FragmentManager fragmentManager;

//    private FragmentTransaction fragmentTransaction;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fragmentManager = getFragmentManager();
        initUI();
    }

    private void initUI() {
        // 初始化底部栏
        bottom_bar = (Bottom_bar)findViewById(R.id.bottom_bar);
        bottom_bar.setBottomBarClickListener(this);
        // 切换fragement
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.top_bar, new HomeFragment());
        fragmentTransaction.commit();
    }

    @Override
    public void onItemClick(int action) {
        FragmentTransaction transaction = fragmentManager.beginTransaction();;
        switch (action) {
            case R.id.frag_main_liner :
                transaction.replace(R.id.top_bar, new HomeFragment());
                break;
            case R.id.frag_category_liner :
                transaction.replace(R.id.top_bar, new CategoryFragment());
                break;
            case R.id.frag_shopcar_liner :
                transaction.replace(R.id.top_bar, new ShopFragment());
                break;
            case R.id.frag_mine_liner :
                transaction.replace(R.id.top_bar, new MineFragment());
                break;
        }
        transaction.commit();
    }
}
